def prost(r):
    g = 0
    for i in range(2, r):
        if r % i == 0:
            g += 1
    if g == 0:
        return True
    else:
        return False

d = {"zero": '0',
     "one": '1',
     "two": '2',
     "three": '3',
     "four": '4',
     "five": '5',
     "six": '6',
     "seven": '7',
     "eight": '8',
     "nine": '9'}
s = input().split()
if s[0] not in d or s[1] not in d or s[2] not in d:
    print('Wrong input')
elif len(s) != 3:
    print('Wrong input')
elif s[0] == "zero":
    print('Wrong input')
else:
    strl = d[s[0]] + d[s[1]] + d[s[2]]
    n = int(strl)
    l = n
    l2 = 0
    r = n
    r2 = 0

    if prost(n):
        print(n)
    else:
        while not prost(l):
            l -= 1
            if prost(l):
                l2 = l
                break
        while not prost(r):
            r += 1
            if prost(r):
                r2 = r
                break
        if r2 - n < n - l2:
            print(r2)
        else:
            print(l2)